import { useLocation, useNavigate } from 'react-router-dom'
import { useDispatch } from 'react-redux'
import { Dispatch } from '@/store'

export default function Login() {
  const dispatch = useDispatch<Dispatch>()
  const location = useLocation()
  const navigate = useNavigate()

  const get = () => {
    console.log(location)
  }

  const login = async () => {
    await dispatch.app.login({
      username: 'admin',
      password: '123123'
    })
    const redirect = window.location.search
    navigate(redirect ? redirect.split('=')[1] : location.state?.path ?? '/')
  }

  return (
    <>
      <h2 onClick={get}>这里是登录页面</h2>
      <div onClick={login}>登录</div>
    </>
  )
}
